package customerEnter.Frame.count;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import customerEnter.Frame.Utils.DateUtils;
import customerEnter.Frame.Utils.Log4j;

/**
 * spring 動態代理
 * 
 * 类名称：methodTimeCount 类描述： 创建人：dy 创建时间：2016-6-20 上午11:24:34
 * 
 */
public class MethodTimeCount {

	/**
	 * 環繞通知
	 */
	public void CircularNotification(ProceedingJoinPoint joinpoint) {
		// System.out.println(joinpoint.getKind()); 線程名字
		System.out.println("類：" + joinpoint.getTarget().getClass().getName() + "  方法："
				+ joinpoint.getSignature().getName());
		Log4j.setLog4j(joinpoint.getTarget().getClass());
		Long time1 = DateUtils.dateToUnixTimestamp();
		// System.out.println(joinpoint.getThis().getClass().getName());//代理對象
		// System.out.println(joinpoint.getSignature().getName());// 運行的方法名
		try {
			joinpoint.proceed();
		} catch (Throwable e) {
			Log4j.Log4JOutError(e.getMessage());
		}
		Long time2 = DateUtils.dateToUnixTimestamp();
		System.out.println("運行了：" + (time2 - time1) + " 毫秒");
	}

	/**
	 * 最終通知　
	 */
	public void applaud(JoinPoint join) {
		System.out.println("方法結束");
	}

	/**
	 * 異常通知
	 */
	public void doThrowing(JoinPoint jp, Throwable ex) {
		System.out.println("method " + jp.getTarget().getClass().getName() + "." + jp.getSignature().getName()
				+ " throw exception");
		System.out.println(ex.getMessage());
	}

}
